package se.webbzon.oschi01.worldcamera;

import javax.media.j3d.Canvas3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.View;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import se.webbzon.oschi01.friendly.Friendly;

@Deprecated
public class DefaultWorldCamera implements WorldCamera {
	
	// The available properties of the WorldCamera
	public static final int	TRANSPARENCY	= (1<<0);
	
	// The transform group of the camera
	//private final TransformGroup cameraTransformGroup;
	
	// The view associated with this camera
	//private final View view;
	
	//private final ViewingPlatform vwp;
	
	private final Canvas3D canvas;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new WorldCamera which will project the captured
	 * content onto the provided Canvas3D. **/
	@Friendly DefaultWorldCamera(Canvas3D canvas) {
		this(0,canvas);
	}
	
	/** Creates a new WorldCamera which will project the captured
	 * content onto the provided Canvas3D. The camera can be
	 * given special properties based on the purpose of the camera. 
	 * If the properties are set to zero then no special properties 
	 * will be applied. **/
	@Friendly DefaultWorldCamera(int cameraProperties, Canvas3D canvas) {
		this.canvas = canvas;
		/*cameraTransformGroup = new TransformGroup();
		cameraTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        cameraTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);*/
        
        //view = new View();
        
		// Add view platform, physical body and physical environment to view
        //vwp = new ViewingPlatform();
        
		//ViewPlatform vp = new ViewPlatform();
        //Viewer v = new Viewer(canvas);
        //v.setViewingPlatform(vwp);
        //view = v.getView();
        //cameraTransformGroup = vwp.getViewPlatformTransform();
		//view.attachViewPlatform(vp);
		/*PhysicalBody pb = new PhysicalBody();
		view.setPhysicalBody(pb);    
		PhysicalEnvironment pe = new PhysicalEnvironment();
		view.setPhysicalEnvironment(pe);*/
		
		// Add the provided canvas to the view
		//view.addCanvas3D(canvas);
		
		// Apply the given properties
		//if (isSet(cameraProperties,TRANSPARENCY))
			//v.getView().setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY);

		// Attach the view platform to the camera transform group
		//cameraTransformGroup.addChild(vwp);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the java3d view of the world camera. This method
	 * should only be used by a the WorldView or JWorldView. **/
	public View getView() {
		return canvas.getView();
	}
	
	/** Returns the java3d node associated with this instance. This method
	 * should only be used by an instance of WorldView or JWorldView. **/
	/*public Node getNode() {
		return vwp;
	}*/
	

	@Override public void projectPerspective(Point3d from, Point3d to, Vector3d up) {
		Transform3D t = new Transform3D();
		t.lookAt(from,to,up);
		t.invert();
		//canvas.getView().getViewPlatform().getParent()
		//cameraTransformGroup.setTransform(t);
	}
	
	/** Sets the minimal distance between the camera and the object
	 * for which the camera still projects the object. Object closer
	 * than the minimal distance will not be visible. **/
	@Override public void setProjectionMinDistance(double minDistance) {
		//vwp.getViewers()[0].getView().setFrontClipDistance(minDistance);
	}
	
	/** Sets the maximal distance between the camera and the object
	 * for which the camera still projects the object. Object further
	 * away than the maximal distance will not be visible. **/
	@Override public void setProjectionMaxDistance(double maxDistance) {
		//vwp.getViewers()[0].getView().setBackClipDistance(maxDistance);
	}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Returns true if the given property is set in the given properties. **/
	/*private static final boolean isSet(int properties, int property) {
		return ((properties & property) == property);
	}*/

}
